package com.study.javaBasic.valuetype.string;

import java.util.StringJoiner;

public class TestMain {
    public static void main(String[] args) {
/** String StringBuilder StringJoiner核心类
 * //String核心类
 String s=new String(new char[]{ '1','2','3'},1,2);
 s=s.substring(0,1);
 System.out.println(s);
 s=new String(new int[]{ 65,66,67},0,3);
 System.out.println(s);
 s = "A,,B;C ,D";
 s=s.replaceAll("[\\,\\;\\s]+", ",");
 System.out.println(s);
 s = "A,B,C,D";
 String[] ss = s.split(",");
 System.out.println(Arrays.toString(ss));
 System.out.println(Integer.getInteger("java.version"));
 //StringBuilder核心类
 StringBuilder sb = new StringBuilder(1024);
 //StringBuilder之所以不用重新赋值,是因为内部方法不返回新的对象
 //在后面加入
 sb.append("Mr ")
 .append("Bob")
 .append("!")
 //在前方加入
 .insert(0, "Hello, ");
 System.out.println(sb.toString());
 //StringJoiner核心类:将字符串数组以特定的字符隔开
 String[] names = {"Bob", "Alice", "Grace"};
 StringJoiner sj = new StringJoiner(", ","Hello,","!");
 for (String name : names) {
 sj.add(name);
 }
 System.out.println(sj.toString());
 System.out.println(String.join(",",names));*/
/**
 * StringJoiner构造一个SELECT语句：
 */
        String[] fields = {"name", "position", "salary"};
        String table = "employee";
        String select = buildSelectSql(table, fields);
        System.out.println(select);
        System.out.println("SELECT name, position, salary FROM employee".equals(select) ? "测试成功" : "测试失败");
    }

    static String buildSelectSql(String table, String[] fields) {
        // TODO:
        StringJoiner joiner = new StringJoiner(", ", "SELECT ", " FROM " + table);
        for (String field : fields) {
            joiner.add(field);
        }
        return joiner.toString();
    }

}
